<template>
	<view class="contentB">
		<text class="title">子组件B</text>
		<view class="b-box">
			<text>comA组件传进来的值：</text>
			<text class="red-text">{{result}}</text>
		</view>
		<view class="b-box">
			<view class="text-area">
				<text>回传值：</text>
				<input type="text" v-model="callBackValue" style="color: blueviolet;" />
				<button @click="sendOutside()" size="mini">回传</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "comB",
		data() {
			return {
				result: '', 
				callBackValue: ''
			};
		},
		methods: {
			sendOutside() {
				console.warn("comB-----sendOutside--->" + this.callBackValue);
				this.$emit('callBackFun', this.callBackValue);
			},
			handleGetIntent(msg) {
				console.error("-----comB---getIntent--->" + msg);
				this.result = msg;
			}
		},
		mounted() { 
			uni.$on('getIntent', this.handleGetIntent);
		},
		beforeDestroy() { 
			uni.$off('getIntent', this.handleGetIntent);
		}
	};
</script>

<style>
	.contentB {
		background-color: greenyellow;
		padding: 20rpx;
		margin-top: 35rpx;
		width: 600rpx;
		margin: 0 auto;
	}

	.title {
		font-size: 50rpx;
		display: block;
		text-align: center;
		margin-bottom: 30rpx;
		font-weight: bold;
	}

	.b-box {
		margin-bottom: 30rpx;
	}

	.red-text {
		font-weight: bold;
		color: red;
	}

	.text-area {
		display: flex;
	}
</style>